<<<<<<< HEAD
import React, { useState,useEffect} from "react"
import { Button, Table  , Form, Input, message} from 'antd';
import { useDispatch, useSelector } from 'umi'

import styles from  "./css/questionTypes.less"
const IndexPage: React.FC = () => {
  const [data2,setdata2] = useState()
  const [flag,setFlag] = useState<boolean>(false)
  const dispatch = useDispatch()
  const { data } = useSelector(module => (module as { addQuestions: { data: [] } }).addQuestions)
  const [form] = Form.useForm();
  const inputLayout = {
      wrapperCol: {span: 24}
  }
  const {list}=useSelector(models=>(models as {user:{list:object[]}}).user)
  useEffect(()=>{
      dispatch({
          type: 'addQuestions/getQuestionType'
      })
  },[flag])
  function handleAdd(){
      setFlag(true)
  }
  function onFinish(value:{text:string,sort:number}){
      let values=value
      let num=data.length+1
      console.log("ssssssssss",list)
      values={
          ...values,
          sort:num
      }
    let result=dispatch({
      type:'addQuestions/insertQuestionsType',
      payload:values
     });
     (result as unknown as Promise<{code: number, msg: string}>).then(res=>{
         console.log(res)
          if(res.code===1){
              message.success(res.msg);
              setFlag(false)
          }else{
            message.error(res.msg);
            setFlag(true)
          }
          form.resetFields();
     })
  }
  function cancel(){
      setFlag(false)
  }
=======
import React , {useState,useEffect} from "react"
import {useDispatch, useSelector} from "umi"
import styles from "./questionTypes.less"
import { Form, Input, Button, message } from 'antd';
>>>>>>> de54b307166b277708c9f443ac2c9a94aa3cb036

const questionTypes:React.FC=()=>{
    let dispatch = useDispatch()
    const [flag,setFlag] = useState<boolean>(false)
    const [form] = Form.useForm();
    const inputLayout = {
        wrapperCol: {span: 24}
    }
    const {list}=useSelector(models=>(models as {user:{list:object[]}}).user)
    useEffect(()=>{
        dispatch({
            type:"user/getList"
        })
        dispatch({
            type: 'question/getQuestionType'
        })
    },[flag])
    function addTypes(){
        setFlag(true)
    }
    function onFinish(value:{text:string,sort:number}){
        let values=value
        let num=list.length+1
        console.log("ssssssssss",num)
        values={
            ...values,
            sort:num
        }
      let result=dispatch({
        type:'question/insertQuestionsType',
        payload:values
       });
       (result as unknown as Promise<{code: number, msg: string}>).then(res=>{
           console.log(res)
            if(res.code===1){
                message.success(res.msg);
                setFlag(false)
            }else{
              message.error(res.msg);
              setFlag(true)
            }
            form.resetFields();
       })
    }
    function cancel(){
        setFlag(false)
    }
    return <div className={styles.wrap}>
        <h1>试题分类</h1>
        <div className={styles.box}>
            <button className={styles.btn} onClick={addTypes}>+ 添加试题</button>
            <div className={styles.head}>
                <span>类型ID</span>
                <span>类型名称</span>
                <span>操作</span>
            </div>
            <div className={styles.body}>
                {
                    list&&list.map((item,index)=>{
                        return <div key={index}>
                            <div>
                                <span>
                                    {(item as {questions_type_id:string}).questions_type_id}
                                </span>
                                <span>
                                    {(item as {questions_type_text:string}).questions_type_text}
                                </span>
                                <span></span>
                            </div>
                        </div>
                    })
                }
            </div>
        </div>
        {
<<<<<<< HEAD
          key: index,
          name: item.questions_type_id,
          chinese: item.questions_type_text,
        },
      )
    })
    setdata2(data1)
  }, [data])
  function onChange(pagination: any, filters:any, sorter:any, extra:any) {
    console.log('params', pagination, filters, sorter, extra);
  }
  return (
    <div className={styles.wrap}>
      <h1>试题分类</h1>
      <Button onClick={handleAdd} type="primary" style={{ marginBottom: 16 }}>
              +添加类型
            </Button>
      <Table columns={columns} dataSource={data2} onChange={onChange} />
      
      
    <div>
    {
=======
>>>>>>> de54b307166b277708c9f443ac2c9a94aa3cb036
           flag&&<div className={styles.shade} > 
                    <div>
                        <Form onFinish={onFinish} form={form} initialValues={{
                            text:''
                        }}>
                            <h3>创建新类型</h3>
                            <Form.Item
                                name='text'
                                rules={[{ required: true, message: '请输入类型名称!' }]}
                                {...inputLayout}
                            >
                                <Input placeholder='请输入类型名称' className={styles.input}/>
                            </Form.Item>
                            <div className={styles.btns}>
                            <Button className={styles.sub} type="primary" htmlType="submit">确认</Button>
                            <input type="button" value='取消' className={styles.none} onClick={cancel}/>
                            </div>
                        </Form>
                    </div>
            </div>
        }
        
    </div>
}
 
export default questionTypes